package com.zf.museum.utils;

import org.apache.poi.ss.usermodel.Cell;

import java.text.DecimalFormat;

public class ExcelUtil {

    public static final int CELL_TYPE_NUMERIC = 0;//数值型
    public static final int CELL_TYPE_STRING = 1;//字符串型
    public static final int CELL_TYPE_BLANK = 3;//空值
    public static final int CELL_TYPE_BOOLEAN = 4;//布尔型
    public static final int CELL_TYPE_ERROR = 5;//错误

    public static String getCellValue(Cell cell) {

        String cellValue = "";
        DecimalFormat df = new DecimalFormat("#");
        switch (cell.getCellType()) {
            case CELL_TYPE_NUMERIC:
                cellValue = df.format(cell.getNumericCellValue()).toString();
                break;
            case CELL_TYPE_STRING:
                cellValue = cell.getStringCellValue();
                break;
            case CELL_TYPE_BLANK:
                cellValue = "";
                break;
            case CELL_TYPE_BOOLEAN:
                cellValue = cell.getBooleanCellValue()+"";
                break;
            default:
                cellValue = "";
        }

        return cellValue;
    }
}
